﻿using System;
using System.Collections.Generic;
using System.Net.NetworkInformation;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using ig.app.Services.ig.app.Services;
using Xamarin.Forms;

[assembly: Dependency(typeof(ig.app.iOS.DependencyServices.IPAddressManager))]
namespace ig.app.iOS.DependencyServices
{


    class IPAddressManager : IIPAddressManager
    {
        public async Task<string[]> GetIPAddress()
        {
            String ipAddress = "";
            List<string> ipList = new List<string>();

            foreach (var netInterface in NetworkInterface.GetAllNetworkInterfaces())
            {
                if (netInterface.NetworkInterfaceType == NetworkInterfaceType.Wireless80211 ||
                    netInterface.NetworkInterfaceType == NetworkInterfaceType.Ethernet)
                {
                    foreach (var addrInfo in netInterface.GetIPProperties().UnicastAddresses)
                    {
                        if (addrInfo.Address.AddressFamily == AddressFamily.InterNetwork)
                        {
                            //ipAddress = addrInfo.Address.ToString();
                            ipList.Add(addrInfo.Address.ToString());

                        }
                    }
                }
            }

            return ipList.ToArray();
        }

        public async Task<string[]> GetLocalServer()
        {
            //Thread t = new Thread();
            throw new NotImplementedException();
        }
    }
}

